package org.jsbd.boss.util;

/**
 * @(#)AliCheckCodeUtil.java 2016骞�11鏈�30鏃�
 * Copyright(C) 2015 ZHEXIN IT CO.,LTD. All rights reserved.
 */

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 闃块噷鐨勫浘褰㈤獙璇佺爜璇嗗埆
 * 
 * @author <a href="mailto:zhaihuilin@zhexinit.com" >缈熸儬鏋�</a>
 * @version 1.0.0
 */
public class AliCheckCodeUtil {
    public static final Logger LOGGER = LoggerFactory.getLogger(AliCheckCodeUtil.class);

//    public static String APPCODE="APPCODE 4774917d8461414f9a4c76fd954aabec";
    public static String APPCODE="APPCODE 9d7ca358eb654d60a3261a80e8463bf2";
    
   

    /**
     * 
     * 璇嗗埆楠岃瘉鐮�
     * @author <a href="mailto:zhaihuilin@zhexinit.com" >缈熸儬鏋�</a>
     * @param imageBase64 鍥剧墖鏂囦欢鐨刡ase64瀛楃涓层�傚浘鐗囧ぇ灏忛渶瑕佸皬浜�100KB銆�
     * @param typeId    
     * 1.绾暟瀛� typeId=1000 浠绘剰闀垮害鏁板瓧锛岃瘑鍒巼浼氶檷浣� typeId=1010 1浣嶆暟瀛� typeId=1020 2浣嶆暟瀛� ... typeId=1100 10浣嶆暟瀛� </br>
     * 2.绾嫳鏂� typeId=2000 浠绘剰闀垮害鑻辨枃锛岃瘑鍒巼浼氶檷浣� typeId=2010 1浣嶈嫳鏂� typeId=2020 2浣嶈嫳鏂� ... typeId=2100 10浣嶈嫳鏂� </br>
     * 3.鑻辨枃鏁板瓧娣峰悎 typeId=3000 浠绘剰闀垮害鑻辨暟娣峰悎锛岃瘑鍒巼浼氶檷浣� typeId=3010 1浣嶈嫳鏁� typeId=3020 2浣嶈嫳鏁版贩鍚� ... typeId=3100 10浣嶈嫳鏁版贩鍚�</br> 
     * 4.绾眽瀛� typeId=4000 浠绘剰闀垮害姹夊瓧娣峰悎锛岃瘑鍒巼浼氶檷浣� typeId=4010 1浣嶆眽瀛� typeId=4020 2浣嶆眽瀛� ... typeId=4100 10浣嶆眽瀛� </br>
     * 5.鏁板瓧鑻辨枃姹夊瓧娣峰悎 typeId=5000 浠绘剰闀垮害涓嫳鏁颁笁娣�</br>
     * @param convertToJpg 鏈夊皯閲弍ng鎴杇if鍥捐浆鎴恓pg鏍煎紡鍚庤瘑鍒巼鏄庢樉鎻愰珮锛堝苟涓嶆槸鎵�鏈塸ng鎴杇if杞垚jpg鍚庨兘浼氭彁楂樿瘑鍒巼锛夈��
     *  姝ゅ瓧娈典负1鏃惰〃绀洪渶瑕佹妸鍥剧墖杞负jpg鏍煎紡锛屽叾浠栧�间笉鍋氳浆鎹㈡搷浣溿��
     */
    public static String check(String imageBase64, String typeId, String convertToJpg) {
        String host = "http://ali-checkcode.showapi.com";
        String path = "/checkcode";
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        // 鏈�鍚庡湪header涓殑鏍煎紡(涓棿鏄嫳鏂囩┖鏍�)涓篈uthorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", APPCODE);
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("convert_to_jpg", convertToJpg);
        bodys.put("img_base64",imageBase64);
        bodys.put("typeId", typeId);

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            return EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            LOGGER.warn("",e);
        }
        return null;
    }
}
